/**
 * apps里面存放的就是子应用
*/
const apps: any = [
    {
        name: "ReactApp",
        entry: "//localhost:8000",
        container: "#SubAppContainer",
        activeRule: "/react"
    },
    {
        name: "Vue2App",
        entry: "//localhost:8001",
        container: "#SubAppContainer",
        activeRule: "/vue2"
    },
    {
        name: "Vue3App",
        entry: "//localhost:8002",
        container: "#SubAppContainer",
        activeRule: "/vue3"
    }
]

import { registerMicroApps, addGlobalUncaughtErrorHandler, start } from "qiankun";

/**
 * 注册微应用
*/
registerMicroApps(apps, {
    // qiankun 生命周期钩子 - 微应用加载前
    beforeLoad: (app) => {
        console.log("before load", app.name);
        return Promise.resolve();
    },

    afterMount: (app) => {
        console.log("after mount", app.name);
        return Promise.resolve();
    }
})


/**
 * 处理全局异常，子应用可能出现加载失败
*/
addGlobalUncaughtErrorHandler((event) => {
    console.error(event);
    const { message: msg } = event;
    if(msg && msg.includes("died in status LOADING_SOURCE_CODE")) {
        alert("子应用加载失败")
    }
})


export default start